/* eslint-disable multiline-ternary */
import moment from 'moment'
import { User, Video } from 'react-feather'
import { BsFillDoorOpenFill } from 'react-icons/bs'
import { IoLocationOutline } from 'react-icons/io5'

const useAppointmentData = ({ prevData, nextData, checkInAppointments }) => {
  const prev_zoom_google_meetings =
    !!prevData?.telehealth_zoom_id && !!prevData?.telehealth_google_id
  const next_zoom_google_meetings =
    !!nextData?.telehealth_zoom_id && !!nextData?.telehealth_google_id
  const next_booking_data = nextData?.booking !== null
  const prev_booking_data = prevData?.booking !== null

  return [
    {
      id: prevData?.id,
      appointmentTitle: 'Previous Appointment',
      date: prevData?.booking?.start_date
        ? moment.unix(prevData?.booking?.start_date).format('MM/DD/YYYY')
        : prevData?.start_date
        ? moment.unix(prevData?.start_date).format('MM/DD/YYYY')
        : '--',
      time: prevData?.booking?.start_time
        ? ` ${
            moment(prevData?.booking?.start_time, 'HH:mm').format('hh:mm A') ||
            '--'
          } -
      ${moment(prevData?.booking?.end_time, 'HH:mm').format('hh:mm A') || '--'}`
        : prevData?.start_time
        ? ` ${moment(prevData?.start_time, 'HH:mm').format('hh:mm A') || '--'} -
        ${moment(prevData?.end_time, 'HH:mm').format('hh:mm A') || '--'}`
        : '--',
      locationTitle: `${
        prevData?.booking?.location?.name ||
        prevData?.provider_location?.city ||
        '--'
      }`,
      teleHealth: prevData?.telehealth || false,
      address: prev_booking_data
        ? `${prevData?.booking?.location?.address || '--'}`
        : `${prevData?.provider_location?.address || '--'},${
            prevData?.provider_location?.state || '--'
          },${prevData?.provider_location?.zipcode || '--'}`,
      locationIcon: <IoLocationOutline />,
      titleTwo: prevData?.telehealth === true ? 'TeleHealth' : 'Room ',
      iconTwo:
        prevData?.telehealth === true ? <Video /> : <BsFillDoorOpenFill />,
      meeting:
        prevData?.telehealth === false
          ? prevData?.booking?.room?.name
          : prev_zoom_google_meetings
          ? 'Zoom Meeting | Google Meet'
          : !!prevData?.telehealth_zoom_id
          ? 'Zoom Meeting'
          : !!prevData?.telehealth_google_id
          ? 'Google Meet '
          : '--',
      UserIcon: <User />,
      room: '0',
      user: 'With',
      userName: `${
        prevData?.booking?.provider?.first_name ||
        nextData?.provider?.first_name ||
        '--'
      } ${
        prevData?.booking?.provider?.last_name ||
        nextData?.provider?.last_name ||
        '--'
      }`,
      checked: false
    },
    {
      id: nextData?.id,
      appointmentTitle: 'Next Appointment',
      startDate: nextData?.booking?.start_date
        ? nextData?.booking?.start_date
        : nextData?.start_date
        ? nextData?.start_date
        : '--',
      date: nextData?.booking?.start_date
        ? moment.unix(nextData?.booking?.start_date).format('MM/DD/YYYY')
        : nextData?.start_date
        ? moment.unix(nextData?.start_date).format('MM/DD/YYYY')
        : '--',
      startTime: nextData?.booking?.start_time
        ? nextData?.booking?.start_time
        : nextData?.start_time
        ? nextData?.start_time
        : '--',
      time: nextData?.booking?.start_time
        ? ` ${
            moment(nextData?.booking?.start_time, 'HH:mm').format('hh:mm A') ||
            '--'
          } -
      ${moment(nextData?.booking?.end_time, 'HH:mm').format('hh:mm A') || '--'}`
        : nextData?.start_time
        ? ` ${moment(nextData?.start_time, 'HH:mm').format('hh:mm A') || '--'} -
        ${moment(nextData?.end_time, 'HH:mm').format('hh:mm A') || '--'}`
        : '--',
      teleHealth: nextData?.telehealth || false,
      address: next_booking_data
        ? `${nextData?.booking?.location?.address || '--'}`
        : `${nextData?.provider_location?.address || '--'},${
            nextData?.provider_location?.state || '--'
          },${nextData?.provider_location?.zipcode || '--'}`,
      locationTitle: `${
        nextData?.booking?.location?.name ||
        nextData?.provider_location?.city ||
        '--'
      }`,
      locationIcon: <IoLocationOutline />,
      titleTwo: nextData?.telehealth === true ? 'TeleHealth' : 'Room',

      iconTwo:
        nextData?.telehealth === true ? <Video /> : <BsFillDoorOpenFill />,
      meeting:
        nextData?.telehealth === false
          ? nextData?.booking?.room?.name
          : next_zoom_google_meetings
          ? 'Zoom Meeting | Google Meet'
          : !!nextData?.telehealth_zoom_id
          ? 'Zoom Meeting'
          : !!nextData?.telehealth_google_id
          ? 'Google Meet '
          : '--',
      room: '0',
      user: 'With',
      UserIcon: <User />,
      userName: `${
        nextData?.booking?.provider?.first_name ||
        nextData?.provider?.first_name ||
        '--'
      } ${
        nextData?.booking?.provider?.last_name ||
        nextData?.provider?.last_name ||
        '--'
      }`,
      checked: nextData?.checked_in || false,
      checkInAppointments
    }
  ]
}

export default useAppointmentData
